package com.yanqu.road.entity.decoration;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.DataObject;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class UserMammon extends DataObject {

	/**
	 * 玩家编号
	 */
	private long userId;
	/**
	 * 膜拜时间
	 */
	private long worshipTime;
	/**
	 * 获得神迹技能
	 */
	private int mammonSkillId;
	/**
	 * 生效次数
	 */
	private int effectTimes;

	private long totalWorshipTimes;

	private long resetTime;

	private Map<Integer, MammonCongratulateTime> congratulateTimeMap = new ConcurrentHashMap<>();

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		if (this.userId != userId) {
			this.userId = userId;
			setUpdateOption();
		}
	}

	public long getWorshipTime() {
		return worshipTime;
	}

	public void setWorshipTime(long worshipTime) {
		if(this.worshipTime != worshipTime) {
			this.worshipTime = worshipTime;
			setUpdateOption();
		}
	}

	public int getMammonSkillId() {
		return mammonSkillId;
	}

	public void setMammonSkillId(int mammonSkillId) {
		if(this.mammonSkillId != mammonSkillId) {
			this.mammonSkillId = mammonSkillId;
			setUpdateOption();
		}
	}

	public int getEffectTimes() {
		return effectTimes;
	}

	public void setEffectTimes(int effectTimes) {
		if(this.effectTimes != effectTimes) {
			this.effectTimes = effectTimes;
			setUpdateOption();
		}
	}

	public long getTotalWorshipTimes() {
		return totalWorshipTimes;
	}

	public void setTotalWorshipTimes(long totalWorshipTimes) {
		if(this.totalWorshipTimes != totalWorshipTimes) {
			this.totalWorshipTimes = totalWorshipTimes;
			setUpdateOption();
		}
	}

	public long getResetTime() {
		return resetTime;
	}

	public void setResetTime(long resetTime) {
		if(this.resetTime != resetTime) {
			this.resetTime = resetTime;
			setUpdateOption();
		}
	}

	public Map<Integer, MammonCongratulateTime> getCongratulateTimeMap() {
		return congratulateTimeMap;
	}

	public String getCongratulateTimeMapJson() {
		return JSON.toJSONString(congratulateTimeMap);
	}

	public void setCongratulateTimeMap(Map<Integer, MammonCongratulateTime> congratulateTimeMap) {
		this.congratulateTimeMap = congratulateTimeMap;
		setUpdateOption();
	}

	public MammonCongratulateTime getCongratulateTime(int type){
		if(hasCongratulateTime(type)){
			return congratulateTimeMap.get(type);
		}
		return null;
	}

	public MammonCongratulateTime setCongratulateTime(int type, long recordTime, long congratulateTime){
		MammonCongratulateTime mammonCongratulateTime;
		if(!hasCongratulateTime(type)){
			mammonCongratulateTime = new MammonCongratulateTime();
			mammonCongratulateTime.setType(type);
			mammonCongratulateTime.setRecordTime(recordTime);
			mammonCongratulateTime.setCongratulateTime(congratulateTime);
			congratulateTimeMap.put(type, mammonCongratulateTime);
		}else {
			mammonCongratulateTime = getCongratulateTime(type);
			mammonCongratulateTime.setRecordTime(recordTime);
			mammonCongratulateTime.setCongratulateTime(congratulateTime);
		}
		setUpdateOption();
		return mammonCongratulateTime;
	}

	public boolean hasCongratulateTime(int type){
		return congratulateTimeMap.containsKey(type);
	}
}
